package org.xx.armory.swing.builders;

import org.xx.armory.objectparser.LineInfo;
import org.xx.armory.objectparser.ParsedObject;

public class CellModel
        extends ParsedObject {
    private final ComponentModel child;
    private final int rowNo;
    private final int columnNo;
    private final int rowSpan;
    private final int columnSpan;
    private final ModelAlignment horizontalAlignment;
    private final ModelAlignment verticalAlignment;
    private final int horizontalStretch;
    private final int verticalStretch;
    private final int margin;

    /**
     * 构造单元格模型。
     *
     * @param lineInfo
     *         源文件中的位置信息。
     * @param rowNo
     *         单元格的行号，从0开始。
     * @param columnNo
     *         单元格的列号，从0开始。
     * @param rowSpan
     *         单元格的水平扩展格数，最小是1。
     * @param columnSpan
     *         单元格的垂直扩展格数，最小是1。
     * @param horizontalAlignment
     *         单元格的水平对齐方式，{@link ModelAlignment#NONE}表示采用对应列的对齐方式。
     * @param verticalAlignment
     *         单元格的垂直对齐方式，{@link ModelAlignment#NONE}表示采用对应行的对齐方式。
     * @param margin
     *         单元格的内部边距。
     * @param child
     *         单元格的内部组件，可以是布局。
     */
    protected CellModel(
            LineInfo lineInfo,
            int rowNo,
            int columnNo,
            int rowSpan,
            int columnSpan,
            ModelAlignment horizontalAlignment,
            ModelAlignment verticalAlignment,
            int horizontalStretch,
            int verticalStretch,
            int margin,
            ComponentModel child
    ) {
        super(lineInfo);
        this.rowNo = rowNo;
        this.columnNo = columnNo;
        this.rowSpan = rowSpan;
        this.columnSpan = columnSpan;
        this.horizontalAlignment = horizontalAlignment;
        this.verticalAlignment = verticalAlignment;
        this.horizontalStretch = horizontalStretch;
        this.verticalStretch = verticalStretch;
        this.margin = margin;
        this.child = child;
    }

    public final int getRowNo() {
        return this.rowNo;
    }

    public final int getColumnNo() {
        return this.columnNo;
    }

    public final int getRowSpan() {
        return this.rowSpan;
    }

    public final int getColumnSpan() {
        return this.columnSpan;
    }

    public final ModelAlignment getHorizontalAlignment() {
        return this.horizontalAlignment;
    }

    public final ModelAlignment getVerticalAlignment() {
        return this.verticalAlignment;
    }

    public final int getHorizontalStretch() {
        return this.horizontalStretch;
    }

    public final int getVerticalStretch() {
        return this.verticalStretch;
    }

    public final int getMargin() {
        return this.margin;
    }

    /**
     * 获取单元格内部的组件，可能是一个布局。
     *
     * @return 单元格内部的组件，如果此单元格内部不包含则返回{@code null}。
     */
    public final ComponentModel getChild() {
        return this.child;
    }
}
